package cn.xp.dml;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDML {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/db_test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false";
        // 1) 创建连接对象
        Connection connection = DriverManager.getConnection(url, "root", "123456");
        // 2) 创建 Statement 语句对象
        Statement statement = connection.createStatement();
        // 3) 执行 SQL 语句：executeUpdate(sql)
        int count = 0;
        // 4) 返回影响的行数
        count += statement.executeUpdate("insert into student values(null, '孙悟空', 1, '1993-03-24')");
        count += statement.executeUpdate("insert into student values(null, '白骨精', 0, '1995-03-24')");
        count += statement.executeUpdate("insert into student values(null, '猪八戒', 1, '1903-03-24')");
        count += statement.executeUpdate("insert into student values(null, '嫦娥', 0, '1993-03-11')");
        System.out.println("插入了" + count + "条记录");
        // 5) 释放资源
        statement.close();
        connection.close();
    }
}
